package com.fymxy.question_bank_management.controller;

import com.fymxy.question_bank_management.pojo.*;
import com.fymxy.question_bank_management.service.*;
import com.fymxy.question_bank_management.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.PrivateKey;

@RestController
public class LoginController {

//    @Autowired
//    private LoginServiceImpl loginService;

    @Autowired
    private StudentService studentLoginService;

    @Autowired
    private TeacherService teacherLoginService;

    @Autowired
    private ManagerService managerLoginService;

    @PostMapping("/login")
    public ApiResult login(@RequestBody Login login){

        String usertype = login.getUsertype();
        String username = login.getUsername();
        String password = login.getPassword();

        switch (usertype){
            case "0":
                Manager managerRes = managerLoginService.managerLogin(username,password);
                return ApiResultHandler.buildApiResult(200, "请求成功", managerRes);

            case "1":
                Teacher teacherRes = teacherLoginService.teacherLogin(username,password);
                return ApiResultHandler.buildApiResult(200, "请求成功", teacherRes);

            case "2":
                Student studentRes = studentLoginService.studentLogin(username,password);
                return ApiResultHandler.buildApiResult(200, "请求成功", studentRes);

            default:               return ApiResultHandler.buildApiResult(400, "请求失败", null);
        }
    }
}
